#include "Block.h"
#include "MainLayer.h"
USING_NS_CC;

CBlock::CBlock():
	m_color(eBC_Red),
	m_fBlockSize(59.2f)
{
	for (int i=0; i<6; ++i)
	{
		m_pSprite[i] = NULL;
	}
}

void CBlock::init()
{
	m_pSprite[0] = CCSprite::spriteWithFile("Images\\Palette\\redBlock.png", CCRect(0,0,m_fBlockSize,m_fBlockSize));
	m_pSprite[1] = CCSprite::spriteWithFile("Images\\Palette\\blueBlock.png", CCRect(0,0,m_fBlockSize,m_fBlockSize));
	m_pSprite[2] = CCSprite::spriteWithFile("Images\\Palette\\yellowBlock.png", CCRect(0,0,m_fBlockSize,m_fBlockSize));
	m_pSprite[3] = CCSprite::spriteWithFile("Images\\Palette\\purpleBlock.png", CCRect(0,0,m_fBlockSize,m_fBlockSize));
	m_pSprite[4] = CCSprite::spriteWithFile("Images\\Palette\\orangeBlock.png", CCRect(0,0,m_fBlockSize,m_fBlockSize));
	m_pSprite[5] = CCSprite::spriteWithFile("Images\\Palette\\greenBlock.png", CCRect(0,0,m_fBlockSize,m_fBlockSize));

	for (int i=0; i<6; ++i)
	{
		MainLayer::getRootLayer()->addChild(m_pSprite[i], -1);
		m_pSprite[i]->setIsVisible(false);
	}
	
	m_pSprite[0]->setIsVisible(true);
}

void CBlock::destroy()
{
// 	if (m_pSprite)
// 	{
// 		HelloWorld::getRootLayer()->removeChild(m_pSprite, false);
// 		//m_pSprite->release();
// 		//delete m_pSprite;
// 		m_pSprite = NULL;
// 	}
}

//////////////////////////////////////////////////////////////////////////
void CBlock::changeColor( int color )
{
	changeColor((EBlk_Color)color);
}

void CBlock::changeColor( EBlk_Color color )
{
	m_color = color;

	for (int i=0; i<6; ++i)
	{
		m_pSprite[i]->setIsVisible(false);
	}

	m_pSprite[(int)color - 2]->setIsVisible(true);
}

void CBlock::setPos( const CCPoint& pos )
{
	for (int i=0; i<6; ++i)
	{
		m_pSprite[i]->setPosition(pos);
	}
}
//////////////////////////////////////////////////////////////////////////
void CBlock::hide()
{
	for (int i=0; i<6; ++i)
	{
		m_pSprite[i]->setIsVisible(false);
	}
}
//////////////////////////////////////////////////////////////////////////
void CBlock::display()
{
	for (int i=0; i<6; ++i)
	{
		m_pSprite[i]->setIsVisible(false);
	}

	m_pSprite[(int)m_color - 2]->setIsVisible(true);
}
